package com.by.mq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @author ServivE
 * @version 0.1
 * @className RabbitConfig
 * @description
 * @date 2024/10/24 17:38
 * @since jdk17
 */
@Component
public class RabbitConfig {

    /**
     * 生成订单的队列
     *
     * @return
     */
    @Bean
    public Queue queue() {
        //队列持久化  防止枪到订单  mq服务器关闭了 消息丢失（订单消失）
        return QueueBuilder.durable("orderQueue")
                .ttl(30 * 60 * 1000)//消息（订单）存活时间
                .build();
    }
    @Bean
    public Queue lazyQueue(){
        return new Queue("lazyQueue");
    }

    /**
     * 延迟交换顺路
     * @return
     */
    @Bean
    public LazyExchange lazyExchange(){
        return new LazyExchange("lazyEx");
    }

    @Bean
    public Binding bindingLazy(Queue lazyQueue, LazyExchange lazyExchange){
        return BindingBuilder.bind(lazyQueue).to(lazyExchange).with("lazy").noargs();
    }


}
